email me at borlaj@portlandschools.org

Loading
notes previous (12/<12) submit the dump links  
 

HWJ3 - Using the scanner class: (This counts as 9 points)

Start with the code below and use it to create the 9 methods described.

 
/*
 * @author Jeff Borland   -> Replace w/ your name
 * @date 10-2-14
 */

import java.util.Scanner;
public class HWJ3_Scanner
{
    public void testOfScannerClass()
    {
        //You need to initialize the scanner in order to use it
        Scanner scan=new Scanner(System.in);  
        //test of reading Strings
        System.out.println("Type in a string");
        String theString=scan.nextLine();        
        System.out.println("In case you forgot, you just typed " + theString);

        //test of reading int
        System.out.println("Type in an integer");
        int theInt=scan.nextInt();        
        System.out.println("In case you forgot, you just typed " + theInt);

        //test of reading double
        System.out.println("Type in a decimal");
        double theDouble=scan.nextDouble();        
        System.out.println("In case you forgot, you just typed " + theDouble);                       
    }     

    //Create a method that will ask your name and age and then
    // find how many years older mr borland is then you (im 37)
    //it will spit out Mr Borland is 15 yrs older than Charlie
    public void ageDiff()
    {
        Scanner scan=new Scanner(System.in);  
        //YOUR CODE GOES HERE
    } 

    //Create a method that will convert meters to centimeters and also inches.
    //It will ask for meters and then print out the number of cms and inches
    public void convertMeters()
    {
        Scanner scan=new Scanner(System.in);  
        //YOUR CODE GOES HERE
    }

    //Ask for a weight in pounds convert to kilograms.  
    //it would say 180 pounds is 81.6466266 kilograms (convert by pounds*.453592
    public void convertToKilograms()
    {
        //You will need the following line in all methods in order to initialize the scanner.
        Scanner scan=new Scanner(System.in);  

        //add your code here        
    } 

    //Ask the user for their dogs name and age.  You will then convert the dogs age in to years by multiplying by 7 and then saying:
    //Your dog Lassie is 42 yrs old.
    public void findDogsAge()
    {
        //You will need the following line in all methods in order to initialize the scanner.
        Scanner scan=new Scanner(System.in);  

        //add your code here

    }   

    //Ask the user for their first and last name and then they will say:
    //Jeff Borland, there are 4 letters in your first name and 7 in your last.
    public void findLettersInName()
    {
        //You will need the following line in all methods in order to initialize the scanner.
        Scanner scan=new Scanner(System.in);  

        //add your code here

    } 

    //Ask the user for 2 numbers and spit out the average
    public void findAvg()
    {
        //You will need the following line in all methods in order to initialize the scanner.
        Scanner scan=new Scanner(System.in);  

        //add your code here

    } 

    //Ask the user for their height in feet and inches (read both things seperately).
    // Then spit out You are 75 inches tall.
    public void findHeight()
    {
        //You will need the following line in all methods in order to initialize the scanner
        Scanner scan=new Scanner(System.in);  
    }

    //ask for tax rate and price of item and it will display total price
    // ie if item is 50 and tax is 5 (as in 5%), the total price is 52.50.
    public void totalPrice ()
    {
        //You will need the following line in all methods in order to initialize the scanner
        Scanner scan=new Scanner(System.in);  
    }

    //Advanced Students - must do at least 2 of the 5 below (look at notes on if statements, loops)
    //Ask the user for a number of miles for a taxi ride and then ask for
    // cost per mile and pickup cost. 
    //Then spit out total charge (which is #of miles *cost per mile + pickup cost
    public void findTaxiCost()
    {
    }

    //This will ask the user for the speed he was going and then spit out
    //the cost of a ticket (from 0-65 - $0, 66-74 - $85, 75-100 - $200 101+ - $1000
    public void findTicket()
    {
    }

    //This will find out the number of people who dressed up for spirit week
    //Ask the user 5 times (for each day) how many people dressed up [like how many people dressed up on day1? etc]
    //Then spit out the total
    //you must use a for loop
    public void find5DayTotal()
    {
    }

    //This will ask the user how many games they played, then it will find the winning percent 
    //So the user might say 3, and the program will ask them 3 times if they won
    //So they might say y,n,n and then it will spit out you won 33.3% of the time
    public void findWinningPrct()
    {
    }

    //create a method that will keep asking for a grade until the user hits -1.  They will then
    //find the average of those grades
    // you will need to use loops
    public void findAverage()
    {
    }	

}    

 
Advanced Students -notes on if statements, loops)